﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public abstract class CmsPublishedEntityObject : CmsSiteEntityObject, IPublishedEntityObject
    {
        #region Properties

        public DateTime? PublishStartDate { get; set; }

        public DateTime? PublishEndDate { get; set; }

        public bool IsPublished { get; set; }

        [XmlIgnore]
        [ScriptIgnore]
        public bool IsCurrentlyPublished
        {
            get
            {
                var currentDate = DateTime.Now;

                return IsPublished ?
                    (currentDate >= DatePublished) && (currentDate <= PublishEndDate.GetValueOrDefault(DateTime.MaxValue)) :
                    false;
            }
        }

        [XmlIgnore]
        [ScriptIgnore]
        public DateTime DatePublished
        {
            get
            {
                return PublishStartDate.HasValue ? PublishStartDate.Value : DateCreated;
            }
        }

        #endregion
    }
}
